Ext.onReady(function(){
	var centerPart=null;
	var topPart=Ext.create('Ext.toolbar.Toolbar',{
		items:[{
			xtype:'datefield',
			fieldLabel: '日期',
			labelWidth: 40,
			id:'querytime',
			name:'querytime',
			editable:false,
			format: 'Y-m-d',
			value: new Date()
		},{
			id:'queryByDay',
			xtype:'button',
			enableToggle:true,
			toggleGroup:'timeGroup',
			text:'日查询',
			iconCls:'search', 
			handler:function(){
				createGridStore('day');
			}
		},{
			id:'queryByMonth',
			xtype:'button',
			enableToggle:true,
			toggleGroup:'timeGroup',
			text:'月查询',
			iconCls:'search', 
			handler:function(){
				createGridStore('month');
			}
		}]
	});
	
	function createGridStore(qm){
		var waitMask = new Ext.LoadMask(Ext.getBody(), {     
            msg : "正在加载,请稍后..."    
        }); 
		waitMask.show(); 
		mainPart.remove(centerPart);
		var ct=Ext.getCmp('querytime').getValue();
		Ext.Ajax.request({
			url : '/resourcecontrol/courseschedul_query/',
			params:{querymode:qm,querytime: Ext.util.Format.dateRenderer('Y-m-d')(ct)},
			method : 'post',
			success : function(response) {
				waitMask.hide();
				var json = Ext.JSON.decode(response.responseText);
				if(json.success != null && json.success==false){
					Ext.Msg.alert('系统提示', json.message);
					return;
				}
				
			    Ext.define('json_data',{
			        extend: 'Ext.data.Model',
			        fields: json.metaData.fields
			    });
			    var store = Ext.create('Ext.data.Store', {
			        model: 'json_data',
			        data:json.rows,
				    proxy: {
				        type: 'memory',
				        reader: {
				            type: 'json',
				            root: 'rows',
				            totalProperty: 'totalCount'
				        }
				    }
			    });
			    centerPart = Ext.create('Ext.grid.Panel',{
			        store: store,
			        autoHeight: true,
			        //selModel:Ext.create('Ext.selection.CheckboxModel'),
			        columnLines:true,
			        columns: json.columns,
			        layout : 'fit',
			        loadMask:true,
			        viewConfig: {
			        	stripeRows: true,
			            listeners: {
			                itemdblclick: function(dataview, record, item, index, e) {
			                	selecttime=record.get('singledate');
			                	if(selecttime){
			                		Ext.getCmp('querytime').setValue(new Date(Date.parse(selecttime.replace(/-/g, "/"))));
			                		createGridStore('day');
			                	}
			                }
			            }
			        }
			    });
			    mainPart.add(centerPart);
			}
		});		
	}	
	
	
	
	var mainPart=Ext.create('Ext.container.Container',{
		renderTo: 'courseschedulquery-panel',
		autoScroll:true,
	    height: 800,
	    layout: {
	        align: 'stretch',
	        type: 'vbox'
	    },
		items:[topPart]		
	});
//	var mainPart=Ext.create('Ext.container.Viewport',{
//		//layout:'fit',
//		autoScroll:true,
//		autoShow:true,
//		layout: {
//	        align: 'stretch',
//	        type: 'vbox'
//	    },
//		renderTo: 'courseschedulquery-panel',
//		items:[topPart]
//	});	
});